package mypractice;

import javax.swing.Timer;

import observer.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Clock extends ASubject<Integer>{

	
	private Timer timer ; 
	
	public Clock(){
		
		timer = new Timer(1000, new ActionListener(){
			int value = 100;
			public int getValue(){return value;}
			@Override
			public void actionPerformed(ActionEvent e) {
				if(value==0 ) value = 100;
				setState(value--);
				
			}});
		timer.start();
	}
	
	
	
	
	@Override
	public void setState(Integer value) {
		
		
		state = value ; 
		notifyObservers();
		
	}

	@Override
	public Integer getState() {
		return state;
	}


	
}
